﻿@{
	Layout = null;
}

<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
	<title>授权登录</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
	<meta http-equiv="Pragma" content="no-cache" />
	<meta http-equiv="Expires" content="0" />
	<script src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js" asp-append-version="true"></script>
	<script>
		var globalData = {
			baseUrl: '@(Context.Request.PathBase)',
			extInfo:@Html.Raw(ViewBag.ExtInfo),
			userInfo:@Html.Raw(ViewBag.UserInfo)
		};
	</script>
</head>
<body>
	<div id="error" style="margin:0 auto;text-align:center;color:#f00;"></div>
	<script>
		wx.miniProgram.getEnv(function (res) {
			try {
				if (!res.miniprogram) {
					throw new Error('请在小程序中打开');
				}
				if (!globalData.extInfo) {
					throw new Error('回调页面参数为空');
				}
				if (!globalData.userInfo || !globalData.userInfo.openid) {
					throw new Error('未获取到相关用户信息');
				}
				if (!globalData.extInfo.page) {
					throw new Error('回调页面参数为空');
				}
				//var params = Object.assign({}, globalData.userInfo, {
				//	state: globalData.extInfo.state
				//});
				//var pageUrl = globalData.extInfo.page + "?result=" + JSON.stringify(params);
				var pageUrl = globalData.extInfo.page + "?result=" + JSON.stringify(globalData.userInfo);
				wx.miniProgram.navigateTo({
					url: pageUrl
				});
			} catch (err) {
				document.getElementById('error').innerHTML = '请求出错：' + (err.message || err);
			}
		});
	</script>
</body>
</html>